﻿
<CascadingAuthenticationState>
    <Modules.Core.Blazor.Layouts.Components.MyErrorBoundary>
        <ChildContent>
            @*AdditionalAssemblies用于添加其他项目中的razor页面*@
            <Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="_PageRouteData.AdditionalPages">
                <Found Context="routeData">
                    <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Modules.Core.Blazor.Layouts.MainLayout)">
                        <Authorizing>
                            <h2 style="text-align:center"><Icon Type="loading" Theme="outline"></Icon>正在进行身份验证...</h2>
                        </Authorizing>
                        <NotAuthorized>
                            @if (context.User.Identity == null)
                            {
                                <RedirectToLogin />
                            }
                            else
                            {
                                <Result Status="403" Title="无权访问" SubTitle="未经授权的访问" />
                            }
                        </NotAuthorized>
                    </AuthorizeRouteView>

                    @*导航到新页面时，FocusOnNavigate 组件将焦点设置到页面的顶层元素*@
                    <FocusOnNavigate RouteData="@routeData" Selector="input" />
                </Found>
                <NotFound>
                    <Modules.Core.Blazor.Pages.PageResult._404 />
                </NotFound>
            </Router>
            <AntDesign.AntContainer @rendermode="@InteractiveServer" />
        </ChildContent>
    </Modules.Core.Blazor.Layouts.Components.MyErrorBoundary>
</CascadingAuthenticationState>
@code {
    //全局捕获错误，后续页面导航事件中将其重置为非错误状态
    private ErrorBoundary? errorBoundary;
    protected override void OnParametersSet()
    {
        errorBoundary?.Recover();
    }
}